<template>
  <view>
    <wyb-popup ref="popup" type="center" radius="6" :showCloseIcon="false" :scrollY="true" height="580" width="600">
      <view class="yuanba">
        <view class="text-xl">{{$t('help.sygzdr')}}</view>
      </view>
      <p class="text">{{$t('sys.tab12')}}</p>
      <view class="cu-list menu">
        <view class="foot">
          <button class="bg-blues" @tap="watchClose">{{$t('yuan.qx')}}</button>
          <button class="bg-blue" @tap="handSubmit">{{$t('yuan.dr')}}</button>
        </view>
      </view>

    </wyb-popup>
  </view>
</template>

<script>
  import wybPopup from '@/components/wyb-popup/wyb-popup.vue'
  // #ifdef  APP-PLUS
  import _sql from '@/util/sql.js';
  // #endif
  export default {
    components: {
      wybPopup
    },
    data() {
      return {
        config: {},
        sqllist: []
      }
    },
    mounted() {

    },
    methods: {
      handSubmit() {
        this.zaiApi({
          url: this.config.book_source_book,
        }).then(async (res) => {
          this.$refs.popup.close();
          await this.install(res)
           this.$emit('flags',1)
        });
        this.zaiApi({
          url: this.config.book_source_yuan,
        }).then(async (res) => {
          this.$refs.popup.close();
          uni.setStorageSync('shukudata', res);
          this.$emit('flags', this.data)
        });
      },
      async install(arr) {
        var _this = this;
        arr.forEach(element => {
          _sql.insertSQL(element).then(function(res) {});
        })
       
      },
      onChange(is) {

        var _this = this;
        this.config = uni.getStorageSync('config')
      
        if (this.config.book_source && this.config.book_source_book && this.config.book_source_yuan) {
          if (is == 1) {
            if (uni.getStorageSync('shukudata') == '' || uni.getStorageSync('shukudata') == false || uni.getStorageSync(
                'shukudata') == undefined) {
              this.$refs.popup.show();
            }else{
              this.watchClose()
            }
          }
            // #ifdef  APP-PLUS
          if (is == 2) {
           _sql.selectSQL("select * from " + this.dbs + "").then(function(res) {
             if (res.length <= 0 || res.length == undefined) {
               _this.$refs.popup.show();
             }else{
               _this.watchClose()
             }
           });
               //修改子组件的内容
          }
		   // #endif  
        }
      },
      watchClose() {
        this.$refs.popup.close();
      },
    }
  }
</script>

<style>
  .img-box {
    height: 120rpx;
    width: 220rpx;
  }

  .jh {
    color: #027ce1;
    margin-left: 30rpx;

  }

  .bg-blues {
    width: 30%;
    height: 80rpx;
    line-height: 80rpx;
    margin: 0 auto;
    display: black;
    margin-top: 190rpx;
    background-color: #eee;
  }

  .bg-blue {
    width: 30%;
    height: 80rpx;
    line-height: 80rpx;
    margin: 0 auto;
    display: black;
    margin-top: 190rpx;
  }

  .yuanba {
    background-color: #027ce1;
    color: #fff;
    padding: 20rpx;
  }

  .text {
    padding: 30rpx;
  }

  .foot {
    display: flex;
  }
</style>
